// ---------------------------------------------------------------------
//
// -- 超越现实界面
// -- author £
//
// ---------------------------------------------------------------------

const PROGRESS_W = 650,
    UPDATE_TIME = 0.2;

cc.Class({
    extends: cc.Component,

    properties: {
        head: cc.Sprite,
        iosLayer: cc.Node,
        anLayer: cc.Node,
        startScore: cc.Label,
        endScore: cc.Label,
        lbPercent: cc.Label,
        selfNode: cc.Node,
    },

    ctor: function () {
        this._maxScore = 0;
        this._pStartX = - PROGRESS_W * 0.5;
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        let isIOS = require('AppInfo').isIOS;

        this.anLayer.active = !isIOS;
        this.iosLayer.active = isIOS;
        this.reset();
    },

    start () {
    },

    updateScore: function (start, end, percent) {
        this.startScore.string = start;
        this.endScore.string = end;
        this.lbPercent.string = percent + '%';
        this.selfNode.stopAllActions();
        this.selfNode.runAction(
            cc.moveTo(
                UPDATE_TIME, 
                this._pStartX + PROGRESS_W * percent * 0.01,
                this.selfNode.y)
        );
    },

    reset: function () {
        this.selfNode.stopAllActions();
        this.selfNode.x = this._pStartX;
        this.lbPercent.string = '0%';
    },

    setHead: function (data) {
        if (data.headimgurl && data.userid) {
            require('Platform').setHead(data.headimgurl, data.userid, this.head);
        }
    },

    // update (dt) {},
});
